<template>
  <div>
    <!-- <x-header :left-options="{backText: ''}" class="ret" >
      <span >卡劵信息</span>
    </x-header> -->

    <!-- 返回 -->
    <div class="back" @click="goBack">
      <i class="iconfont icon-back"></i>
    </div>

    <div class="main" ref="cardMainRef">
      <div>
        <div class="card" v-if="voucher.bgColor" :style={backgroundColor:voucher.bgColor}>
          <div class="sj-info">

            <img class="logo" v-lazy="voucher.seller.logoImgs" :onerror="defaultImg">
            <p class="sj-title ">{{voucher.seller.name}}</p>
          </div>
          <div class="cart-info">
            <p class="zk-title">{{voucher.mingc}}</p>
            <p class="zk-desc">{{voucher.beiz}}</p>
            <p class="zk-desc">截止日期：{{voucher.jiesrqFaj | formatDate}}</p>

          </div>

        </div>

        <divider v-if="voucher.xiangxnr">备注</divider>
        <div class="cart-defxx" v-if="voucher.xiangxnr" v-html="voucher.xiangxnr">

        </div>
        <!-- <div class="cart-def" :style={backgroundColor:background}>
        <div v-show="iscart  && !ismsg">
          <barcode v-model="vcode" :options="{height:60,width:1.3,displayValue:false,marginBottom:1,background:background}"></barcode>
          <p class="cart-num">{{spritStr(vcode)}}</p>
          <p class="cart-desc">{{voucher.beiz1}}</p>
        </div>
        <div v-show="!iscart && !ismsg">
          <div class="cart-btn">
            <x-button type="primary" :style={backgroundColor:voucher.bgColor} @click.native="getvoucher">领取卡劵</x-button>
            <p class="cart-desc">{{msg}}</p>
          </div>

        </div>
        <div v-show="ismsg">
          <div class="cart-btn">
            <p>{{msg}}</p>
          </div>

        </div>

      </div> -->

        <divider>购买须知</divider>
        <!--使用条件  -->
        <p v-if="voucher.qiyJe>0" class="cart-det-title">使用条件</p>
        <div v-if="voucher.qiyJe>0" class="cart-defxx">
          <ul>
            <li>消费满￥{{voucher.qiyJe}}起用</li>
          </ul>
        </div>
        <p v-if="voucher.xiaofSj" class="cart-det-title">使用时间</p>
        <div v-if="voucher.xiaofSj" class="cart-defxx" v-html="voucher.xiaofSj">

        </div>

        <p v-if="voucher.buksyRq" class="cart-det-title">不可用日期</p>
        <div v-if="voucher.buksyRq" class="cart-defxx" v-html="voucher.buksyRq">

        </div>
        <p v-if="voucher.shiyFw" class="cart-det-title">适用范围</p>
        <div v-if="voucher.shiyFw" class="cart-defxx" v-html="voucher.shiyFw">

        </div>
        <p v-if="voucher.shifYy" class="cart-det-title">是否预约</p>
        <div v-if="voucher.shifYy" class="cart-defxx" v-html="voucher.shifYy">

        </div>
        <p v-if="voucher.shiyGz" class="cart-det-title">使用规则</p>
        <div v-if="voucher.shiyGz" class="cart-defxx" v-html="voucher.shiyGz">

        </div>

        <divider>商家信息</divider>
        <div class="sj-defxx">
          <ul>
            <li>商家电话：{{voucher.seller.telephone}}</li>
            <li>商家地址：{{voucher.seller.address}}</li>
          </ul>
        </div>
      </div>
    </div>

    <div class="foot">
      <span class="pic">￥{{voucher.zongJe}}</span>
      <span class="pic-old">价值￥{{voucher.dikJine}}</span>
      <x-button class="btn" mini @click.native="goPay">立即抢购</x-button>
    </div>

  </div>
</template>
<script>
import { Divider, XButton, XHeader } from "vux";
import { sign, signStr } from "@/assets/js/sign.js";
import BScroll from "better-scroll";
import { formatDate } from "@/assets/js/utils.js";
export default {
  components: {
    Divider,
    XButton,
    XHeader
  },
  data() {
    return {
      background: "#fff",
      backgroundcart: "#ffdd1d",
      iscart: false,
      voucher: null,
      vcode: "f8d9b5eef8533628",
      fxrid: 0,
      hyid: 0,
      ismsg: false,
      msg: ""
    };
  },
  methods: {
    init(code, fxrid, hyid) {
      this.fxrid = fxrid;
      this.hyid = hyid;
      let params = signStr("/v1/api/voucher/getVoucher");
      this.$http
        .get(
          "voucher/getVoucher?vcode=" + code + "&pthyid=" + hyid + "&" + params
        )
        .then(res => {
          if (res.data.code === 1) {
            this.voucher = null;
            this.voucher = res.data.resultObject;
            if (this.voucher.cartNum == 0) {
              this.iscart = false;
              this.vcode = "";
            }
            if (this.voucher.cartNum == 1) {
              this.iscart = true;
              this.vcode = this.voucher.code;
            }
            if (this.voucher.cartNum > 1) {
              this.iscart = false;
              this.vcode = "";
              this.msg = "已购买" + this.voucher.cartNum + "张卡劵";
            }
            this.$nextTick(() => {
              this._initScroll();
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    spritStr(str) {
      let str1 = str.replace(/\s/g, "").replace(/(.{4})/g, "$1-");
      if (str1.substr(str1.length - 1, 1) == "-") {
        str1 = str1.substr(0, str1.length - 1);
      }
      return str1;
    },
    goBack() {
      this.$router.back(-1);
    },
    getvoucher() {
      
    },
    goPay(){
      this.$router.push({
          name: 'VoucherPay',params:{'voucher':this.voucher,'fxrid':this.fxrid,'hyid':this.hyid}
        });
    },
    _initScroll() {
      if (this.voucher) {
        if (!this.cardScroll) {
          // console.log(this.$refs.cardMainRef);
          this.cardScroll = new BScroll(this.$refs.cardMainRef, {
            click: true,
            scrollX: false
          });
        } else {
          this.cardScroll.refresh();
        }
      }
    }
  },
  created() {
    let code = this.$route.params.code;
    let fxrid = this.$route.params.fxrid;
    let hyid = this.$route.params.hyid;
    if (fxrid == null || fxrid == undefined) {
      fxrid = 0;
    }
    if (hyid == null || hyid == undefined) {
      hyid = 0;
    }
    // this.$vux.toast.text(this.$store.memberInfoPt, "top");
    // alert(this.$store.memberInfoPt)
    this.init(code, fxrid, hyid);
  },
  filters: {
    formatDate(time) {
      var date = new Date(time);
      return formatDate(date, "yyyy-MM-dd");
    }
  }
};
</script>

<style lang="sass">
@import "~@/assets/scss/mixin.scss";
.cart-defxx 
  padding: 10px 10px 0 18px
  font-size: 14px
  line-height: 20px
  ul
    list-style-type: disc
  ol
    list-style-type: decimal
  li
    padding: 0 0 10px 0 
    margin-left: 10px

.sj-defxx
  padding: 1px 10px 0 18px
  font-size: 12px
  line-height: 16px
  ul,ol
    list-style-type: disc
  li
    padding: 0 0 10px 0 
    margin-left: 10px
</style>


<style scoped lang="less">
.main {
  position: absolute;
  top: 10px;
  padding: 10px 10px 0 10px;
  bottom: 100px;
  background-color: #fff;
  overflow: hidden;
  .card {
    /* 相对定位，方便让before和after伪元素绝对定位偏移 */
    position: relative;
    width: 100%;
    height: 186px;
    background-color: #ffdd1d;
    .sj-info {
      height: 60px;
      .logo {
        float: left;
        margin-left: 10px;
        margin-top: 10px;
        width: 50px;
        height: 50px;
        -moz-border-radius: 50px;
        -webkit-border-radius: 50px;
        border-radius: 50px;
        display: inline;
      }
      .sj-title {
        margin-left: 10px;
        line-height: 60px;
        font-size: 16px;
        color: #fff;
        display: inline;
      }
    }
    .cart-info {
      .zk-title {
        width: 100%;
        color: #fff;
        font-size: 28px;
        text-align: center;
      }
      .zk-desc {
        width: 100%;
        padding-top: 10px;
        color: #fff;
        font-size: 14px;
        text-align: center;
      }
    }
  }

  // .card:before,
  // .card:after {
  //   content: " ";
  //   height: 100%;
  //   /* 绝对定位进行偏移 */
  //   position: absolute;
  //   top: 0;
  // }

  // .card:before {
  //   /* 圆点型的border */
  //   border-right: 10px dotted white;
  //   /* 偏移一个半径，让圆点的一半覆盖div */
  //   left: -5px;
  // }

  // .card:after {
  //   /* 圆点型的border */
  //   border-left: 10px dotted white;
  //   /* 偏移一个半径，让圆点的一半覆盖div */
  //   right: -5px;
  // }

  .cart-def {
    text-align: center;
    width: 100%;
    height: 150px;

    .cart-num {
      font-size: 22px;
      text-align: center;
    }
    .cart-desc {
      width: 100%;
      padding-top: 10px;
      font-size: 14px;
      text-align: center;
    }
    .cart-btn {
      padding: 40px;
    }
  }

  .cart-det-title {
    width: 100%;
    font-size: 14px;
    color: #ffa500;
  }
}

.foot {
  padding: 0px 10px 0 10px;
  position: fixed;
  left: 0;
  bottom: 54px;
  width: 100%;
  height: 46px;
  z-index: 10;
  line-height: 46px;
  border-top: 1px solid #b4b4b3;
  .pic {
    line-height: 46px;
    font-size: 30px;
    color: #00bd29;
  }
  .pic-old {
    font-size: 16px;
    color: #797979;
  }

  .btn {
    float:right;
    margin-right: 20px;
    margin-top: 6px;
      background-color: #ffa500;
      color: #fff;
      font-size: 16px;
      text-align: left;
      // font-weight: 700;
  }
}
// 返回按钮
.back {
  position: fixed;
  top: 0px;
  left: 20px;
  width: 35px;
  height: 35px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1;
  i {
    display: block;
    padding-left: 6px;
    padding-top: 2px;

    font-size: 20px;
    color: #fff;
  }
}
</style>
